namespace ScrumSprintMonitor.Implementation.AvailableTimeCalculator
{
	#region #using Directives

	using System;
	using System.Diagnostics;

	using Infrastructure;
	using Infrastructure.Configuration;

	#endregion

	public class TeamMemberFreeBusyInfo : ITeamMemberFreeBusyInfo
	{
		private static readonly TimeSpan SlotSize = TimeSpan.FromMinutes(15);
		private readonly IFreeBusyInfoConfiguration freeBusyInfoConfiguration;

		public TeamMemberFreeBusyInfo(IFreeBusyInfoConfiguration freeBusyInfoConfiguration)
		{
			if (freeBusyInfoConfiguration == null)
			{
				throw new ArgumentNullException("freeBusyInfoConfiguration");
			}

			this.freeBusyInfoConfiguration = freeBusyInfoConfiguration;
		}

		#region Implementation of ITeamMemberFreeBusyInfo

		public bool IsBusy(ITeamMemberInformation teamMemberInfo, DateTime dateTime)
		{
			return teamMemberInfo.IsBusy(dateTime, SlotSize);
		}

		public bool HasFreeBusyInformationFor(ITeamMemberInformation teamMemberInfo)
		{
			return false;
		}

		public bool IsWorkDayFor(ITeamMemberInformation teamMemberInfo, DateTime dateTime)
		{
			if (this.freeBusyInfoConfiguration.ExcludeWeekends)
			{
				var dayOfWeek = dateTime.DayOfWeek;

				return (dayOfWeek != DayOfWeek.Saturday && dayOfWeek != DayOfWeek.Sunday);
			}

			return true;
		}

		public TimeSpan FreeBusySlotSize
		{
			[DebuggerStepThrough]
			get { return SlotSize; }
		}

		#endregion
	}
}